/*
 * Copyright 2008 the original author Ang Gao.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * SearchResultView.java 2008-11-11
 */
package ie.ucc.cs.anggao.finalproject.client.ui.mainpanel.infopane;

import ie.ucc.cs.anggao.finalproject.client.model.SearchEngine;
import ie.ucc.cs.anggao.finalproject.client.model.SearchEngineResult;
import ie.ucc.cs.anggao.finalproject.client.support.css.CSSManager;
import ie.ucc.cs.anggao.finalproject.client.support.searchengine.ResultLink;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DisclosurePanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * @author GaoAng
 *
 */
public class SearchResultView extends Composite{

	private DisclosurePanel mainPanel = null;
	private VerticalPanel results = new VerticalPanel();
	private SearchEngine engine;
	
	public SearchResultView(SearchEngine engine) {
		this.engine = engine;
		mainPanel = new DisclosurePanel(engine.getName());
		initWidget(mainPanel);
		mainPanel.setContent(results);
		mainPanel.setStyleName(CSSManager.SearchResultsView);
		
	}
	
	public void clearResults(){
		results.clear();
		mainPanel.setOpen(true);
	}
	
	public void addSearchResult(SearchEngineResult result){
		VerticalPanel resultItem = new VerticalPanel();
		ResultLink title = new ResultLink(result.getTitle(), result.getUrl());
		HTML description = new HTML(result.getDescription());
		resultItem.add(title);
		resultItem.add(description);
		resultItem.addStyleName(CSSManager.ResultItem);
		title.setStyleName(CSSManager.searchResultLink);
		description.setStyleName(CSSManager.searchResultDescription);
		results.add(resultItem);
		
	}
	
	public SearchEngine getSearchEngine(){
		return this.engine;
	}
	
	
	
}

